import dotenv from 'dotenv';
dotenv.config({
  path: '.env',
});
import { AppModule } from './app.module';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import cookieParser from 'cookie-parser';
import express from 'express';
import morgan from 'morgan';
import {
  DocumentBuilder,
  SwaggerDocumentOptions,
  SwaggerModule,
} from '@nestjs/swagger';
import mongoose from 'mongoose';
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.enableCors();
  app.use(cookieParser());
  app.use(express.json());
  // mongoose.set('debug', true);
  app.use(morgan('[:date[iso]] :remote-addr :method :url :status'));
  app.useStaticAssets(`./public/${process.env.VERSION}`);
  const options: SwaggerDocumentOptions = {
    operationIdFactory: (controllerKey: string, methodKey: string) => methodKey,
  };
  const config = new DocumentBuilder()
    .setTitle('个人项目平台')
    .setDescription('啦啦啦')
    .setVersion(process.env.VERSION)
    .build();
  const document = SwaggerModule.createDocument(app, config, options);
  SwaggerModule.setup('api-docs', app, document);
  await app.init();
  console.log('╔╦╗╔═╗╦  ╦╔═╗╔╗ ╦═╗╔═╗╔═╗╔╦╗  ╔═╗╔═╗╔╦╗╔╦╗╔═╗╔╗╔');
  console.log('║║║║ ║╚╗╔╝║╣ ╠╩╗╠╦╝║ ║╠═╣ ║║  ║  ║ ║║║║║║║║ ║║║║');
  console.log('╩ ╩╚═╝ ╚╝ ╚═╝╚═╝╩╚═╚═╝╩ ╩═╩╝  ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝');
  console.log(`Start Time: ${new Date()}`);
  await app.listen(process.env.PORT);
}
bootstrap();
